package cz.anime.ppro.logic;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cz.anime.ppro.model.Comment;
import cz.anime.ppro.repositories.CommentRepository;

@Component
public class CommentComponentImpl implements CommentComponent {

	@Autowired
	private CommentRepository commentRepository;
	
	@Override
	public List<Comment> getComments() {
		return commentRepository.findAll();
	}
	
	@Override
	public List<Comment> getCommentsByContentId(int contentId) {
		return commentRepository.findCommentByContentId(contentId);
	}
	
	@Override
	public Comment getCommentById(int commentId) {
		return commentRepository.findCommentById(commentId);
	}
	
	@Override
	public void createComment(Comment comment) {
		commentRepository.saveAndFlush(comment);
	}
	
	@Override
	public void deleteComment(Comment comment) {
		commentRepository.delete(comment);
	}
	
	@Override
	public void editComment(Comment comment) {
		commentRepository.saveAndFlush(comment);
	}

}
